



print("esp32 lua hello")
buf=byte.create(100)


url='mqtt://mqtts.heclouds.com:1883'
clientId='esp32-gwt'
username='9g50p74r7f'
password='version=2018-10-31&res=products%2F9g50p74r7f&et=1797393255&method=sha1&sign=%2BwSbJuA%2FdCKyuqW0W9wsHnPJMkU%3D'
print("hello lua")
mq=mqtt.create(clientId,url,username,password)
buf:set("zhang mqtt......")
sendTopic='$sys/5VN8GjnK28/test/thing/property/post'
str=[[
{
	"id": "123456789",
	"version": "1.0",
	"params": {
		"Battery": {"value": 80}
	}
}
]]
print(str)
buf:set(str)

function call(tp,topic,data)
    print(tp,topic,data)
    -- print(byte.create(data))
    if tp==1 then
        print("设备连接成功...")
        -- mq:sub("/topic/qos0",0)
        --mq:publish(sendTopic,buf,0,0)
    end
    -- 接收订阅的信息
    if tp==6 then
        print("接收消息:",data)
    end
    
end
mq:callback(call)
r=mq:connect()
print("r:",r)
